﻿using Commonality.Model.Xml;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Merge.BLL
{
    public partial class SeekForm : Form
    {
        public SeekForm()
        {
            InitializeComponent();
        }



        private void SeekForm_Load(object sender, EventArgs e)
        {
            AimFunction.AimFunctionInit();
            TaskDis();
        }
        private void TaskDis()
        {
            RegistrationTormTextBox.Text = "";
            foreach (Tuple<string, int, int> item in AimFunction.AimList)
            {
                RegistrationTormTextBox.Text += item.Item1 + ":" + "-" + item.Item2 + "-" + item.Item3 + "\r\n";
            }
        }
        private void CheckInAimButt_Click(object sender, EventArgs e)
        {
            Tuple<string, int, int> AimNull = new Tuple<string, int, int>("", 0, 0);
            int num = AimFunction.AimList.IndexOf(AimNull) + 1;
            if (num > 0 && num <= 5)
            {
                Tuple<string, int, int> Aim = new Tuple<string, int, int>(AimPnOrMoTextBox.Text, Convert.ToInt16(AimQuanTextBox.Text), 0);
                AimFunction.AimList[num - 1] = Aim;
                AimFunction.WriteAimToXml(num, Aim);
                TaskDis();
            }
            else
            {
                MessageBox.Show("任务已满");
                return;
            }
        }
    }

    public static class AimFunction
    {
        public static string AimPnOrMo;
        public static int AimQuan;
        public static Tuple<string, int> Aim;
        public static List<Tuple<string, int, int>> AimList;
        private static readonly string parameterFeilName = Application.StartupPath + @"\Parameter\AimParameter.xml";
        public static void AimFunctionInit()
        {
            AimList = new List<Tuple<string, int, int>>(5);              //默认支持5个任务
            AimFunctionDataLoad();
        }
        public static void AimFunctionDataLoad()
        {
            for (int i = 0; i < 5; i++)
            {

                AimList.Add(ReadAimToXml(i + 1));
            }
        }

        #region 数据读写
        public static void WriteAimToXml(int num, Tuple<string, int, int> aim)
        {
            XmlOperater.WriteItemToXml(parameterFeilName, "Aim", "T" + num.ToString(), "PnOrMo", aim.Item1.ToString());
            XmlOperater.WriteItemToXml(parameterFeilName, "Aim", "T" + num.ToString(), "Quan", aim.Item2.ToString());
            XmlOperater.WriteItemToXml(parameterFeilName, "Aim", "T" + num.ToString(), "Gain", aim.Item3.ToString());
        }
        public static Tuple<string, int, int> ReadAimToXml(int num)
        {
            Tuple<string, int, int> ret;
            string PnOrMo = XmlOperater.ReadItemFromXml(parameterFeilName, "Aim", "T" + num.ToString(), "PnOrMo");
            int Num = Convert.ToInt16((XmlOperater.ReadItemFromXml(parameterFeilName, "Aim", "T" + num.ToString(), "Quan") == "") ? "0" : XmlOperater.ReadItemFromXml(parameterFeilName, "Aim", "T" + num.ToString(), "Quan"));
            int GainNum = Convert.ToInt16((XmlOperater.ReadItemFromXml(parameterFeilName, "Aim", "T" + num.ToString(), "Gain") == "") ? "0" : XmlOperater.ReadItemFromXml(parameterFeilName, "Aim", "T" + num.ToString(), "Gain"));
            ret = new Tuple<string, int, int>(PnOrMo, Num, GainNum);
            return ret;
        }
        #endregion


        #region 找板方法

        #endregion
    }

}
